package com.ewhale.feitengguest.presenter.user.mine;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.ArticleDetailDto;
import com.ewhale.feitengguest.dto.BalanceDto;
import com.ewhale.feitengguest.dto.RankDto;
import com.ewhale.feitengguest.view.user.mine.InviteView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

public class InvitePresenter extends IPresenter {
    public void loadBalance() {
        mView.showProLoading();
        request(1, ApiHelper.USER_API.laodBalance(),null);
    }

    public void loadArticleDetails(int type) {
        mView.showProLoading();
        request(2, ApiHelper.USER_API.getArticleDetails(type), null);
    }

    public void getRanking() {
        mView.showProLoading();
        request(3, ApiHelper.TASK_API.getRanking(), null);
    }
    public void getLastRanking() {
        mView.showProLoading();
        request(4, ApiHelper.TASK_API.getLastRanking(), null);
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode){
            case 1:
                ((InviteView)mView).showBalance((BalanceDto)result);
                break;
            case 2:
                ((InviteView) mView).showDetail((ArticleDetailDto) result);
                break;
            case 3:
                ((InviteView) mView).showRanking((RankDto) result);
                break;
            case 4:
                ((InviteView) mView).showLastRanking((String) result);
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode,e.getCode(),e.getDisplayMessage());
    }
}
